package o;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.io.File;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import o.crh.b;
import org.json.JSONException;
import org.json.JSONObject;

public class cso {
    public static String ˎ(String str, String str2) {
        String str3 = null;
        try {
            if (!cgy.ˎ(str)) {
                JSONObject jSONObject = new JSONObject(str);
                if (jSONObject.has(str2)) {
                    str3 = jSONObject.getString(str2);
                }
            }
        } catch (JSONException e) {
            crf.ˎ.ˊ("ProductPurchaseUtils", "JSONException");
        }
        return str3;
    }

    public static void ॱ(Context context, String str) {
        if (cgy.ˎ(str)) {
            crf.ˎ.ˋ("ProductPurchaseUtils", "Url is null.");
        } else {
            emz.ॱ(context, "product_purchase_webview", str);
        }
    }

    public static void ˊ(Context context, int i) {
        ˊ(context, context.getResources().getString(i));
    }

    public static void ˎ(Context context, int i, String str) {
        ˊ(context, context.getResources().getString(i, new Object[]{str}));
    }

    public static void ˊ(Context context, String str) {
        if (context == null) {
            context = cre.ˊ();
        }
        evk.ˋ(context, str, 0).ˋ();
    }

    public static boolean ˏ(int i) {
        return i == 3 || i == 4;
    }

    public static String ˋ(Context context) {
        if (context == null) {
            return null;
        }
        if (context instanceof Activity) {
            int ˎ = dgm.ˎ((Activity) context);
            if (ˎ == 17) {
                return ˎ(context, "kidscenter_app_name");
            }
            if (ˎ == 18) {
                return ˎ(context, "educenter_app_name");
            }
        }
        return ˏ(context, context.getPackageName());
    }

    public static String ˎ(Context context, String str) {
        if (context == null) {
            return null;
        }
        Resources resources = context.getResources();
        int identifier = resources.getIdentifier(str, "string", context.getPackageName());
        if (identifier != 0) {
            return resources.getString(identifier);
        }
        return null;
    }

    private static String ˏ(Context context, String str) {
        PackageManager packageManager = context.getPackageManager();
        try {
            CharSequence applicationLabel = packageManager.getApplicationLabel(packageManager.getApplicationInfo(str, DnsConfig.MAX_CACHE_ENTRIES));
            if (applicationLabel != null) {
                return applicationLabel.toString();
            }
        } catch (NameNotFoundException e) {
            crf.ˎ.ˊ("ProductPurchaseUtils", "NameNotFoundException: " + e.toString());
        }
        return null;
    }

    public static String ˎ(String str) {
        File file = new File(str);
        if (file.exists()) {
            byte[] ॱ = ॱ(file);
            StringBuilder stringBuilder = new StringBuilder();
            try {
                MessageDigest instance = MessageDigest.getInstance(AaidIdConstant.SIGNATURE_SHA256);
                instance.update(ॱ);
                for (byte b : instance.digest()) {
                    String toHexString = Integer.toHexString(b & 255);
                    if (toHexString.length() < 2) {
                        stringBuilder.append("0");
                    }
                    stringBuilder.append(toHexString);
                }
                return stringBuilder.toString();
            } catch (NoSuchAlgorithmException e) {
                crf.ˎ.ˏ("ProductPurchaseUtils", "Get sha256 failed: NoSuchAlgorithmException");
                return "";
            }
        }
        crf.ˎ.ˏ("ProductPurchaseUtils", "Get sha256 failed. Apk not exists!");
        return null;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static byte[] ॱ(java.io.File r8) {
        /*
        r0 = 0;
        r6 = 0;
        r1 = new java.io.ByteArrayOutputStream;
        r1.<init>();
        r2 = 1024; // 0x400 float:1.435E-42 double:5.06E-321;
        r3 = new byte[r2];
        r2 = new java.util.zip.ZipFile;	 Catch:{ IOException -> 0x006c, all -> 0x0050 }
        r2.<init>(r8);	 Catch:{ IOException -> 0x006c, all -> 0x0050 }
        r4 = "META-INF/MANIFEST.MF";
        r4 = r2.getEntry(r4);	 Catch:{ IOException -> 0x0029, all -> 0x005c }
        if (r4 == 0) goto L_0x0049;
    L_0x0018:
        r0 = r2.getInputStream(r4);	 Catch:{ IOException -> 0x0029, all -> 0x005c }
        if (r0 == 0) goto L_0x0049;
    L_0x001e:
        r4 = r0.read(r3);	 Catch:{ IOException -> 0x0029, all -> 0x0061 }
        if (r4 <= 0) goto L_0x003d;
    L_0x0024:
        r5 = 0;
        r1.write(r3, r5, r4);	 Catch:{ IOException -> 0x0029, all -> 0x0061 }
        goto L_0x001e;
    L_0x0029:
        r1 = move-exception;
        r1 = r2;
    L_0x002b:
        r2 = o.crf.ˎ;	 Catch:{ all -> 0x0066 }
        r3 = "ProductPurchaseUtils";
        r4 = "get manifest file failed due to IOException";
        r2.ˏ(r3, r4);	 Catch:{ all -> 0x0066 }
        o.dnw.ˎ(r0);
        o.dnw.ˎ(r1);
    L_0x003a:
        r0 = new byte[r6];
    L_0x003c:
        return r0;
    L_0x003d:
        r1 = r1.toByteArray();	 Catch:{ IOException -> 0x0029, all -> 0x0061 }
        o.dnw.ˎ(r0);
        o.dnw.ˎ(r2);
        r0 = r1;
        goto L_0x003c;
    L_0x0049:
        o.dnw.ˎ(r0);
        o.dnw.ˎ(r2);
        goto L_0x003a;
    L_0x0050:
        r1 = move-exception;
        r2 = r0;
        r7 = r0;
        r0 = r1;
        r1 = r7;
    L_0x0055:
        o.dnw.ˎ(r1);
        o.dnw.ˎ(r2);
        throw r0;
    L_0x005c:
        r1 = move-exception;
        r7 = r1;
        r1 = r0;
        r0 = r7;
        goto L_0x0055;
    L_0x0061:
        r1 = move-exception;
        r7 = r1;
        r1 = r0;
        r0 = r7;
        goto L_0x0055;
    L_0x0066:
        r2 = move-exception;
        r7 = r2;
        r2 = r1;
        r1 = r0;
        r0 = r7;
        goto L_0x0055;
    L_0x006c:
        r1 = move-exception;
        r1 = r0;
        goto L_0x002b;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.cso.ॱ(java.io.File):byte[]");
    }

    public static void ˎ(final Context context) {
        cku ˏ = cku.ˏ(context, cku.class, null, context.getResources().getString(b.ʽॱ));
        ˏ.ॱ(new cks() {
            public void enableNetworking() {
                crq.ˎ(context, 1);
            }

            public void upgrade() {
                crf.ˎ.ˋ("ProductPurchaseUtils", "cancel repeat purchase");
                cro.ˏ().ˏ(8);
            }

            public void ˋ() {
            }
        });
        ˏ.ˎ(context);
    }

    public static boolean ॱ(String str, String str2) {
        return str.startsWith("agpms://" + str2 + "/product");
    }

    public static void ˎ(int i, int i2, boolean z) {
        if (i == 0) {
            switch (i2) {
                case 600003:
                    crf.ˎ.ˋ("ProductPurchaseUtils", "The product is sold out.");
                    cro.ˏ().ˏ(4);
                    return;
                case 600006:
                    crf.ˎ.ˋ("ProductPurchaseUtils", "The Not-consume product has been purchased.");
                    if (z) {
                        cro.ˏ().ˏ(6);
                        return;
                    } else {
                        cro.ˏ().ˏ(5);
                        return;
                    }
                case 600007:
                    crf.ˎ.ˋ("ProductPurchaseUtils", "The free product has been purchased.");
                    cro.ˏ().ˏ(6);
                    return;
                default:
                    ˎ(z);
                    return;
            }
        }
        ˎ(z);
    }

    private static void ˎ(boolean z) {
        if (z) {
            ˊ(cro.ˏ().ˎ(), b.ˈ);
            cro.ˏ().ˏ(2);
            return;
        }
        cro.ˏ().ˏ(1);
    }

    public static void ˏ(Activity activity) {
        csi.ˋ(14);
        Context context = activity;
        ((cfj) cdb.ॱ(cfj.class)).ॱ(context, 30003000, "com.huawei.hwid", activity.getResources().getString(b.ʿ), 0);
    }
}
